package jgl.vajra.operator.part.mine.activity;

import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.operator.R;
import jgl.vajra.operator.bean.MyWalletBean;
import jgl.vajra.operator.databinding.ActivityMyWalletBinding;
import jgl.vajra.operator.manager.AccountManager;
import jgl.vajra.operator.manager.IntentManager;
import jgl.vajra.operator.part.mine.contract.MyWalletContract;
import jgl.vajra.operator.part.mine.viewModel.MyWalletViewModel;
import jgl.vajra.operator.widget.databindingadapter.BaseBindingItemPresenter;
import jgl.vajra.operator.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.retrofithelper.utils.AEACCoder;
import jgl.vajra.operator.widget.utils.UIUtils;

@CreateViewModel(MyWalletViewModel.class)
public class MyWalletActivity extends BaseMVVMActivity<MyWalletViewModel, ActivityMyWalletBinding> implements MyWalletContract.View , BaseBindingItemPresenter<MyWalletBean.MyWalletListBean> {

    private SingleTypeBindingAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_wallet;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        // 不可嵌套滑动
        mBinding.recyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        adapter = new SingleTypeBindingAdapter(this, null, R.layout.item_my_wallet);
        mBinding.recyclerView.setAdapter(adapter);
        adapter.setItemPresenter(this);

        requestNetData();
    }

    private void requestNetData() {

        Map<String,Object> map=new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        mViewModel.getMyWalletData(map);
    }

    //提现
    @Override
    public void onWithdrawal() {

    }

    //查看明细
    @Override
    public void onDetailed() {
        IntentManager.toWalletDetailedActivity(this);
    }

    @Override
    public void returnMyWalletData(MyWalletBean data) {
        mBinding.tvBalance.setText(AEACCoder.decrypt(data.sumAmount));
        adapter.refresh(data.data);
    }

    @Override
    public void onItemClick(int position, MyWalletBean.MyWalletListBean itemData) {
        IntentManager.toWithdrawalPageActivity(this, AEACCoder.decrypt(itemData.amount),itemData.type);
    }
}
